<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__CSS__/x-admin.css" media="all">
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                分类名称
            </label>
            <div class="layui-input-inline">
                <select name="category_id">
                    <option value="">请选择分类</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                标题
            </label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" required="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="decs" class="layui-form-label">
                内容简介(255长度)
            </label>
            <div class="layui-input-inline">
                <input type="text" id="decs" name="decs" required="required" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="role" class="layui-form-label">
                缩略图
            </label>
            <div class="layui-input-inline">
                <input type="file" name="file">
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo1">
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
               内容
            </label>
            <div class="layui-input-inline">
                <textarea name="content"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                状态
            </label>
            <div class="layui-input-inline">
                <label for="show">显示</label><input id="show" type="radio" value="0" name="status" class="layui-input">
                <label for="hide">隐藏</label><input id="hide" type="radio" value="1" name="status" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit>
                增加
            </button>
        </div>
    </form>
</div>
<script src="__LIB__/layui/layui.js" charset="utf-8">
</script>
<script src="__JS__/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            $.post('{:url("blog.post/add")}', data.field, function (response) {
                layer.alert(response.msg, {icon: 6}, function (index) {
                    if (response.code == 0) {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    }
                    else {
                        layer.close(index);
                    }
                });

            });
            return false;
        });
        $(function(){
            $.get('{:url("blog.category/getCategory")}',function(response){
                if(response.code==0){
                    var html='<option value="">请选择分类</option>';
                    for(var i in response.data){
                        var row=response.data[i];
                        html+='<option value="'+row.id+'">'+row.name+'</option>';
                    }
                    $('select[name=category_id]').html(html);
                    form.render('select');
                }
            })
        });

    });
</script>
</body>

</html>